package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.manage.domain.EventSurgery;
import com.ruoyi.manage.dto.SurgeryDeviceDto;
import com.ruoyi.manage.vo.SurgeryDeviceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.SurgeryDevice;
import com.ruoyi.manage.service.ISurgeryDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 清点单详细内容等Controller
 *
 * @author zww
 * @date 2025-07-08
 */
@Api
@RestController
@RequestMapping("/manage/surgurydevice")
public class SurgeryDeviceController extends BaseController {
    @Autowired
    private ISurgeryDeviceService surgeryDeviceService;

    /**
     * 查询清点单详细内容
     */
    @ApiOperation("list")
    @PreAuthorize("@ss.hasPermi('manage:surgurydevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurgeryDevice surgeryDevice) {
        startPage();
        List<SurgeryDeviceVo> list = surgeryDeviceService.selectSurgeryDeviceList(surgeryDevice);
        return getDataTable(list);
    }

    /**
     * 导出清点单详细内容
     */
    @PreAuthorize("@ss.hasPermi('manage:surgurydevice:export')")
    @Log(title = "清点单详细内容等", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurgeryDevice surgeryDevice) {
        List<SurgeryDeviceVo> list = surgeryDeviceService.selectSurgeryDeviceList(surgeryDevice);
        ExcelUtil<SurgeryDeviceVo> util = new ExcelUtil<SurgeryDeviceVo>(SurgeryDeviceVo.class);
        util.exportExcel(response, list, "清点单详细内容等数据");
    }

    /**
     * 获取清点单详细内容等详细信息
     */
    @ApiOperation("以id获取")
    @PreAuthorize("@ss.hasPermi('manage:surgurydevice:query')")
    @GetMapping(value = "/{surgeryDeviceId}")
    public AjaxResult getInfo(@PathVariable("surgeryDeviceId") Long surgeryDeviceId) {
        return success(surgeryDeviceService.selectSurgeryDeviceBySurgeryDeviceId(surgeryDeviceId));
    }

    /**
     * 新增清点单详细内容等
     */
    @ApiOperation("新增器械清点单")
    @PreAuthorize("@ss.hasPermi('manage:surgurydevice:add')")
    @Log(title = "清点单详细内容等", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurgeryDevice surgeryDevice) {
        return success(surgeryDeviceService.insertSurgeryDevice(surgeryDevice));
    }

    /**
     * 修改清点单详细内容等
     */
    @PreAuthorize("@ss.hasPermi('manage:surgurydevice:edit')")
    @Log(title = "清点单详细内容等", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurgeryDevice surgeryDevice) {
        return toAjax(surgeryDeviceService.updateSurgeryDevice(surgeryDevice));
    }

    /**
     * 删除清点单详细内容等
     */
    @PreAuthorize("@ss.hasPermi('manage:surgurydevice:remove')")
    @Log(title = "清点单详细内容等", businessType = BusinessType.DELETE)
    @DeleteMapping("/{surgeryDeviceIds}")
    public AjaxResult remove(@PathVariable Long[] surgeryDeviceIds) {
        return toAjax(surgeryDeviceService.deleteSurgeryDeviceBySurgeryDeviceIds(surgeryDeviceIds));
    }

    @ApiOperation("关体腔前等事件")
    @Log(title = "设备事件", businessType = BusinessType.DELETE)
    @PostMapping("/event")
    public AjaxResult event(@RequestBody SurgeryDeviceDto surgeryDeviceDto) {
        return AjaxResult.success(surgeryDeviceService.addEvent(surgeryDeviceDto));
    }
}
